﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data.OleDb;
using System.Configuration;
using System.Web.UI.WebControls;

namespace DocumentManager
{
    public class CommonFunctions
    {
        public static ArrayList GetAllUsersFromDB(){
            OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["DocumentManager.Properties.Settings.TrainingCertificationsConnectionString"].ConnectionString);
            OleDbCommand com = con.CreateCommand();
            String vSql = @"select User_Name, Man_Number from Users order by User_Name";
            com.CommandText = vSql;
            ArrayList allUsers = new ArrayList();
            try
            {
                con.Open();

                OleDbDataReader reader = com.ExecuteReader();

                //cbUsers.Items.Add(new ListItem("Select", "0"));
                //cbUsers.Items.Add("Select:0");
                allUsers.Add(new ListItem("Select", "0"));
                //new ListItem();
                while (reader.Read())
                {
                    //cbUsers.Items.Add(new ListItem(reader[0].ToString(), reader[1].ToString()));
                    //cbUsers.Items.Add(reader[0] + ":" + reader[1]);
                    allUsers.Add(new ListItem(reader[0].ToString(), reader[1].ToString()));
                }
                //cbUsers.DisplayMember = "Text";
                //cbUsers.ValueMember = "Value";
                //cbUsers.DataSource = allUsers;

                reader.Close();
            }
            catch { }
            finally
            {
                con.Close();
            }
            return allUsers;
        }
        
    }

    public class MyListItem
    {
        private String value;
        private String label;

        public MyListItem(String Label, String Value)
        {
            this.value = Value;
            this.label = Label;
        }

        public String Value
        {
            get { return value; }
        }
        public String Label
        {
            get { return label; }
        }

    }
}
